package com.sugon.stream;

import com.sugon.entity.Friend;

import java.util.Arrays;
import static java.util.Comparator.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 流失转换
 */
public class TestStream_map {
    public static void main(String[] args) {
        List<Friend> list = Arrays.asList(new Friend("luoyuan", 20), new Friend("yangj", 17), new Friend("fenhc", 19));

        Stream<Friend> stream = list.stream();
        Stream<Friend> stream2 = stream.filter(s -> s.getAge() < 19);
        // List<Friend> collect = stream2.collect(Collectors.toList());

        /*Stream<String> strea3 = stream2.map(new Function<Friend, String>() {

            @Override
            public String apply(Friend Friend) {
                return Friend.getName();
            }
        });*/

        //把一个对象转换为另一种对象
        Stream<String> stream3 = stream2.map(Friend -> Friend.getName());
        //String collect = stream3.collect(Collectors.joining(","));
        //自然排序
        Stream<String> stream4 = stream3.sorted(comparingInt(String::length));
        List<String> collect = stream4.collect(Collectors.toList());
        System.out.println(collect);

    }
}
